package com.asohofrucol.web;

import org.springframework.beans.factory.annotation.Autowired;

import com.asohofrucol.dto.ParameterDTO;
import com.asohofrucol.service.ParameterService;

public class ComboValueController {
	@Autowired
	ParameterService parameterService;
	private ParameterDTO parameterDTO;

	public ComboValueController() {
		System.out.println("ComboValueController");
		parameterDTO = new ParameterDTO();
	}

	public ParameterService getParameterService() {
		return parameterService;
	}

	public void setParameterService(ParameterService parameterService) {
		this.parameterService = parameterService;
	}

	public String getIdField() {
		return parameterDTO.getIdField();
	}

	public void setIdField(String idField) {
		this.parameterDTO.setIdField(idField);
	}

	public ParameterDTO getParameterDTO() {
		if (this.parameterDTO.getOptions().isEmpty()) {
			System.out.println("Cargando combo field: "
					+ parameterDTO.getIdField() + " desde base de datos ");
			this.parameterDTO = parameterService.findByField(parameterDTO
					.getIdField());
		} else {
			System.out.println("Cargando combo field: "
					+ parameterDTO.getIdField() + " desde cache");
		}
		return parameterDTO;
	}

	public void setParameterDTO(ParameterDTO parameterDTO) {
		this.parameterDTO = parameterDTO;
	}

}
